package com.yanggu.flink.datastream_api.wordcount

import org.apache.flink.api.common.RuntimeExecutionMode
import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment

object StreamBatchWordCount {

  def main(args: Array[String]): Unit = {

    val environment = StreamExecutionEnvironment.getExecutionEnvironment
    environment.setRuntimeMode(RuntimeExecutionMode.BATCH)

    environment.readTextFile(getClass.getResource("/hello.txt").getPath)
      .flatMap(_.split(" "))
      .map((_, 1))
      .keyBy((value: (String, Int)) => value._1)
      .sum(1)
      .print("data print>>>")

    environment.execute("WordCount")
  }

}
